package com.journey.org.ui.knowledge.gankio.list

import android.app.Application
import androidx.databinding.ObservableArrayList
import androidx.databinding.ObservableInt
import androidx.databinding.ObservableList
import androidx.lifecycle.viewModelScope
import com.journey.org.BR
import com.journey.org.R
import com.journey.org.app.HttpManager
import com.mvvmhabit.org.base.BaseViewModel
import com.mvvmhabit.org.binding.command.BindingAction
import com.mvvmhabit.org.binding.command.BindingCommand
import com.mvvmhabit.org.custom.LoadingLayout
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.tatarka.bindingcollectionadapter2.ItemBinding

/**
 * @Date: 2020/12/17 11:31
 * @Author:小妖
 * @Description: 干货文章列表
 */
class GankListViewModel(application: Application) : BaseViewModel(application) {

    var page = 1

    val requestStateField = ObservableInt()

    val onClickAgainLoadCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {

        }
    })

    val onLoadMoreCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {

        }
    })

    val onRefreshCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {

        }
    })

    val itemBinding = ItemBinding.of<GankListItemViewModel>(BR.viewModel, R.layout.gank_list_item)

    val items = ObservableArrayList<GankListItemViewModel>()

    fun loadGankList(type: String) {
        viewModelScope.launch(Dispatchers.Main) {
            if (page == 1) {
                requestStateField.set(LoadingLayout.NETWORK_LOADING)
                items.clear()
            }

        }

    }

}